package com.csi.controller.permission;

import com.alibaba.fastjson2.JSON;
import com.csi.domain.Permission;
import com.csi.domain.Role;
import com.csi.pojo.Result;
import com.csi.service.PermissionService;
import com.csi.service.impl.PermissionServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/permission/findAllController")
public class FindAllController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();
        Result<List<Permission>> result = new Result<>();

        PermissionService permissionService = new PermissionServiceImpl();

        List<Permission> permissions = permissionService.findAll();

        if (permissions != null) {
            result.setCode(200);
            result.setMsg("success");
            result.setDatas(permissions);
        } else {
            result.setCode(400);
            result.setMsg("false");
        }
        out.print(JSON.toJSONString(result));
        out.flush();
        out.close();
    }
}
